package com.xique.door.controller;

import java.util.List;

import com.xique.common.core.utils.poi.ExcelUtil;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.core.web.page.TableDataInfo;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.door.bean.domain.DDeviceAdvert;
import com.xique.door.service.IDDeviceAdvertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 设备广告Controller
 * 
 * @author ww
 * @date 2022-03-11
 */
@Controller
@RequestMapping("/device/advert")
public class DDeviceAdvertController extends BaseController
{
    private String prefix = "oms/advert";

    @Autowired
    private IDDeviceAdvertService dDeviceAdvertService;

    @PreAuthorize(hasPermi = "oms:advert:view")
    @GetMapping()
    public String advert()
    {
        return prefix + "/advert";
    }

    /**
     * 查询设备广告列表
     */
    @PreAuthorize(hasPermi = "oms:advert:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DDeviceAdvert dDeviceAdvert)
    {
        startPage();
        List<DDeviceAdvert> list = dDeviceAdvertService.selectDDeviceAdvertList(dDeviceAdvert);
        return getDataTable(list);
    }

//    /**
//     * 导出设备广告列表
//     */
//    @PreAuthorize(hasPermi = "oms:advert:export")
//    @PostMapping("/export")
//    @ResponseBody
//    public AjaxResult export(DDeviceAdvert dDeviceAdvert)
//    {
//        List<DDeviceAdvert> list = dDeviceAdvertService.selectDDeviceAdvertList(dDeviceAdvert);
//        ExcelUtil<DDeviceAdvert> util = new ExcelUtil<DDeviceAdvert>(DDeviceAdvert.class);
//        return util.exportExcel(list, "advert");
//    }

    /**
     * 新增设备广告
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存设备广告
     */
    @PreAuthorize(hasPermi = "oms:advert:add")
    @Log(title = "设备广告", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DDeviceAdvert dDeviceAdvert)
    {
        return toAjax(dDeviceAdvertService.insertDDeviceAdvert(dDeviceAdvert));
    }

    /**
     * 修改设备广告
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DDeviceAdvert dDeviceAdvert = dDeviceAdvertService.selectDDeviceAdvertById(id);
        mmap.put("dDeviceAdvert", dDeviceAdvert);
        return prefix + "/edit";
    }

    /**
     * 修改保存设备广告
     */
    @PreAuthorize(hasPermi = "oms:advert:edit")
    @Log(title = "设备广告", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DDeviceAdvert dDeviceAdvert)
    {
        return toAjax(dDeviceAdvertService.updateDDeviceAdvert(dDeviceAdvert));
    }

    /**
     * 删除设备广告
     */
    @PreAuthorize(hasPermi = "oms:advert:remove")
    @Log(title = "设备广告", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dDeviceAdvertService.deleteDDeviceAdvertByIds(ids));
    }
}
